package com.lq.memo.controller;

import com.lq.memo.entity.MyResponse;
import com.lq.memo.exception.MyException;
import com.lq.memo.exception.ValidateCodeException;
import com.lq.memo.service.ValidateCodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Map;

/**
 * @ClassName ValidateCodeController
 * @Description
 * @Author LQ
 * @Date 2021/11/27 22:15
 * @Version 1.0
 */
@Controller
@RequestMapping("/code")
public class ValidateCodeController {

    @Autowired
    ValidateCodeService codeService;

    @PostMapping("/createEmailValidateCode")
    public MyResponse createEmailValidateCode( @RequestBody Map<String,Object> map
    ) {
        MyResponse myResponse = new MyResponse();
        try {
            String validateCode2Email = codeService.createValidateCode2Email(map);
            myResponse.success().data(validateCode2Email);
        } catch (ValidateCodeException e) {
            e.printStackTrace();
            myResponse.fail().message(e.toString());
        } catch (MyException e) {
            e.printStackTrace();
            myResponse.fail().message(e.toString());
        } catch (com.lq.email.exception.MyException e) {
            e.printStackTrace();
            myResponse.fail().message(e.toString());
        }catch (Exception e){
            e.printStackTrace();
            myResponse.fail().message(e.toString());
        }
        return myResponse;
    }
}
